package com.example.lock;

import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.CyclicBarrier;

public class Job implements Runnable{
    private  DistributedLock lock;

    private OrderNoProvider provider;

    private CyclicBarrier cyclicBarrier;

    public Job(OrderNoProvider provider, CyclicBarrier cyclicBarrier, DistributedLock lock) {
        this.lock = lock;
        this.provider= provider;
        this.cyclicBarrier = cyclicBarrier;
    }

    public void run() {
        try {
            cyclicBarrier.await();
            String s = lock.acquireLock("121", 12L, 12L);
            if(StringUtils.isNotBlank(s)) {
                Integer no = provider.getNo();
                System.out.println("当前线程"+Thread.currentThread().getName()+"当前获取编号为"+no);
                lock.release(s,"'");
            }
            else{
                System.out.println("当前线程"+Thread.currentThread().getName()+"没有获取到锁处理失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
